package com.tanhua.manager.service;

import com.tanhua.domain.vo.PageResult;
import com.tanhua.domain.vo.UserLocationVo;
import com.tanhua.dubbo.api.db.UserInfoApi;
import com.tanhua.dubbo.api.mongo.UserLocationApi;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ManageService {


    @DubboReference
    private UserInfoApi userInfoApi;
    @DubboReference
    private UserLocationApi userLocationApi;

    /**
     * 用户分页查询
     * @param page
     * @param pagesize
     * @param id
     * @param nickname
     * @param city
     * @return
     */
    public ResponseEntity queryUsers(Integer page, Integer pagesize, Long id, String nickname, String city) {

        PageResult pageResult = userInfoApi.queryUsers(page,pagesize,id,nickname,city);

        return ResponseEntity.ok(pageResult);
    }

    /**
     * 获取用户位置
     * @param userId
     * @return
     */
    public ResponseEntity queryUserLocation(Long userId) {
        UserLocationVo userLocationVo = userLocationApi.queryUserLocation(userId);
        Map map = new HashMap();
        map.put("longitude", userLocationVo.getLongitude());//经度
        map.put("latitude", userLocationVo.getLatitude());//纬度
        System.out.println("返回了地址");
        return ResponseEntity.ok(map);
    }
}
